<template>
  <!-- 应急资源 / 火灾监测 -->
  <div class="Emergency">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/power-grid-picture/tide-chart' }">运行监测</el-breadcrumb-item>
        <el-breadcrumb-item>反恐信息监测</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="box">
      <div class="left">
        <div class="top_city">
          <div class="select_city">地区选择</div>
          <div class="content">
            <div class="item" :class="item.id == cityId ? 'checkStyle' : ''" v-for="(item) in cityData" :key="item.id" @click="checkCity(item.id)">{{ item.name }}</div>
          </div>
        </div>
        <!--  -->
        <div class="voltage_level">
          <div class="select_city">线路电压等级</div>
          <div style="margin: 0 0 10px 56px;">全选</div>
          <div class="content">
            <div class="item" :class="item.state ? 'checkStyle':''" v-for="(item,index) in voltageData" :key="item.id" @click="checkVoltage(item,index)">{{ item.name }}</div>
          </div>
        </div>
      </div>
      <div class="right">
        <div class="top">
          <div class="select_city">相关场所视频</div>
          <div class="content_box">
            <div class="item" v-for="(item,index) in arr" :key="index">
              <div class="video_content">
                <video :id="`flv-${index}`" muted controls controlsList="nodownload" />
                <div class="name">变电站</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

// import { homePageSelete } from "@/api/EmergencyDisposal/zqbs.js";

import "@/assets/style/Emergency.less";
import flv from "flv.js";
import Axios from "axios";
export default {
  name: "FireMonitoring",
  components: {},
  data() {
    return {
      cityData: [
        {
          name: "全省",
          id: 0
        },
        {
          name: "武汉",
          id: 1
        },
        {
          name: "荆州",
          id: 2
        },
        {
          name: "黄石",
          id: 3
        },
        {
          name: "宜昌",
          id: 4
        },
        {
          name: "襄阳",
          id: 5
        },
        {
          name: "孝感",
          id: 6
        },
        {
          name: "荆门",
          id: 7
        },
        {
          name: "黄冈",
          id: 8
        },
        {
          name: "鄂州",
          id: 9
        },
        {
          name: "咸宁",
          id: 10
        },
        {
          name: "十堰",
          id: 11
        },
        {
          name: "随州",
          id: 12
        },
        {
          name: "恩施",
          id: 13
        },
        {
          name: "神龙架",
          id: 14
        }
      ],
      voltageData: [
        {
          name: "1000kV",
          id: 0,
          state: false
        },
        {
          name: "500kV",
          id: 1,
          state: false
        },
        {
          name: "220kV",
          id: 2,
          state: false
        },
        {
          name: "110kV",
          id: 3,
          state: false
        },
        {
          name: "35kV",
          id: 4,
          state: false
        },
        {
          name: "±800kV",
          id: 5,
          state: false
        },
        {
          name: "±500kV",
          id: 6,
          state: false
        },
        {
          name: "±420kV",
          id: 7,
          state: false
        }
      ],
      spUrl: "",
      pc: null,
      flvPlayer: null,
      stream: null,
      arr: [
        "151310000003040557",
        "151310000003040559",
        "151310000003040560",
        "151310000003040562",
        "150210000003020284",
        "150210000003020285",
        "150210000003020286",
        "150210000003020287",
        "150210000003020288"
      ],
      cityId: 0
    };
  },
  mounted() {

  },
  methods: {
    checkCity(val) {
      this.cityId = val;
      this.arr = this.arr.sort(() => Math.random() - 0.5);
    },
    checkVoltage(item, index) {
      this.voltageData[index].state = !item.state;
    },
    play(devCode) {
      const videourl = process.env.VUE_APP_SHIPIN_URL;
      const url = `${videourl}/ems/v1/uvp/api/playvideo?code=${devCode}`;
      Axios.get(url).then(res => {
        if (res.status === 200) {
          let location = res.data.location;
          if (location) {
            const path = location.split("/mediatranscode")[1];
            location = `${videourl}/mediatranscode${path}`;
          }
          var videoElement = document.getElementById(`flv-${devCode}`);
          const flvPlayer = flv.createPlayer({
            type: "flv",
            url: location
          }, {
            autoCleanupSourceBuffer: true, // 对SourceBuffer进行自动清理
            autoCleanupMinBackwardDuration: 10, // 指示进行自动清除时为反向缓冲区保留的持续时间（以秒为单位）。
            isLive: true,
            lazyLoadMaxDuration: 60
          });
          flvPlayer.attachMediaElement(videoElement);
          flvPlayer.load();
          flvPlayer.play();
          this.players.push(flvPlayer);
        }
      });
    }
  }
};
</script>

<style scoped lang="less">
@import "../../../assets/style/DisasterInformation.less";
.Emergency {
  :deep(.el-breadcrumb) {
    font-size: 16px;
    line-height: initial;
  }
  :deep(.el-breadcrumb__inner.is-link) {
    font-weight: 100;
    color: #fff;
  }
  :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
    color: #3270ff;
  }
}
.box {
  width: 98vw;
  height: 78vh;
  margin-top: 10px;
  display: flex;
  color: #fff;
  .left {
    width: 30%;
    height: 100%;
    .top_city {
      height: 30%;
      border: 1px solid #0649d7;
    }
    .voltage_level {
      margin-top: 10px;
      height: 68%;
      border: 1px solid #0649d7;
    }
    .content {
      border-radius: 5px;
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start; /* 替代space-between布局方式 */
      text-align: center;
      padding-left: 25px;
      // justify-content: center !important;
    }

    .item {
      cursor: pointer;
      flex: 1;
      line-height: 28px;
      height: 28px;
      // background-color: #cacaca;
      /* 间隙为5px */
      margin: 0 10px 10px 0;
      /* END */
      /* 这里的10px = (分布个数3-1)*间隙5px, 可以根据实际的分布个数和间隙区调整 */
      width: calc((100% - 12px) / 6);
      /* END */
      /* 加入这两个后每个item的宽度就生效了 */
      min-width: calc((100% - 12px) / 6);
      max-width: calc((100% - 12px) / 6);
      /* END */
    }
    .item:nth-child(5n) {
      /* 去除第3n个的margin-right */
      margin-right: 0;
    }
  }
  .right {
    margin-left: 10px;
    width: 70%;
    height: 100%;
    .top {
      width: 100%;
      height: 100%;
      border: 1px solid #0649d7;
      .content_box {
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        height: 94%;
      }
      .item {
        width: 30%;
        height: 30%;
        border: 1px solid #0649d7;
      }
      .item:nth-child(3n) {
        /* 去除第3n个的margin-right */
        margin-right: 0;
      }
      //
      .video_content {
        width: 100%;
        height: 83%;

        video {
          width: 100%;
          height: 100%;
          object-fit: fill;
        }
        .name {
          padding: 5px 0;
          text-align: center;
          background: rgba(38, 92, 255, 0.45);
        }
      }
    }
  }
}
.select_city {
  background: rgba(38, 92, 255, 0.45);
  height: 30px;
  line-height: 30px;
  padding-left: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 15px;
}
.checkStyle {
  border-radius: 10px;
  border: 1px solid #0649d7;
  color: #ffff00;
  box-sizing: border-box;
}
</style>
